package com.dolphin.common.component.var.model;

import com.dolphin.common.component.model.BaseModel;
import com.dolphin.common.component.var.enums.ValueTypeEnum;
import com.dolphin.common.component.var.enums.VarTypeEnum;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author shida
 */
@Setter
@Getter
@ToString
@EqualsAndHashCode(callSuper = true)
public abstract class BaseVarModel extends BaseModel implements Comparable<BaseVarModel> {

    private String defaultValue;
    private String description;
    private String varCode;
    private String varName;
    private ValueTypeEnum valueType;
    private Integer state;
    private String tag;
    private VarTypeEnum varType;
    private Integer projectId;
    private Integer scenarioId;

    private boolean skipCalculate;

    public BaseVarModel(){

    }

    /**
     * 获取bid值，需要子类实现
     * @return
     */
    public abstract String getBid();

    @Override
    public int compareTo(BaseVarModel o) {
        if(this.getUpdatedTime() == null || o.getUpdatedTime() == null){
            return 0;
        }

        if(this.getUpdatedTime().getTime() - o.getUpdatedTime().getTime() == 0){
            if(this.getId() - o.getId() == 0){
                return 0;
            }else {
                return this.getId() - o.getId() > 0 ? -1 : 1;
            }
        }else {
            return this.getUpdatedTime().getTime() - o.getUpdatedTime().getTime() > 0 ? -1 : 1;
        }
    }
}
